package com.litong.utils.http;

/**
 * Created by litong on 2019/1/21 0021. http实例类
 */
public class URLUtil {
  public static StringBuffer append(String url1, String url2) {
    StringBuffer stringBuffer = new StringBuffer();
    if (url1.endsWith("/") && url2.startsWith("/")) {
      // http://www.baidu.com/ /query
      stringBuffer.append(url1);
      // 删除url1最后一个字符
      stringBuffer.deleteCharAt(stringBuffer.length() - 1);
      stringBuffer.append(url2);
      return stringBuffer;
    } else if (url1.endsWith("/") && !url2.startsWith("/")) {
      // http://www.baidu.com/ query
      stringBuffer.append(url1).append(url2);
      return stringBuffer;
    } else if (!url1.endsWith("/") && url2.startsWith("/")) {
      // http://www.baidu.com /query
      stringBuffer.append(url1).append(url2);
      return stringBuffer;
    } else if (!url1.endsWith("/") && !url2.startsWith("/")) {
      stringBuffer.append(url1).append("/").append(url2);
      return stringBuffer;
    } else {
      stringBuffer.append(url1).append("/").append(url2);
      return stringBuffer;
    }
  }
}
